;(function(){
	$(function(){
	"use strict";
	var $window = $(window),
		$document = $(document);
			const {
		dialog,
		session
	} = require('electron').remote;
	
	/* ************************************************************ */
		
	var m_Homepage = { 
		createNew: function () {
			if(!(window.basePage) || typeof(window.basePage.createNew) !=='function'){
				window.basePage={};
				window.basePage.createNew=function(){
					return {};
				}
			}
			var $internal = window.basePage.createNew();
		
			$internal.Nav = null;
			$internal.init = function () { 
				this.Methods = new $Methods();

			};
			
			var $Methods = new Class({ 
				initialize: function () {
					this._init();
				}
			});
			$Methods.extend({ 
				_init: function () {
					this._initDom();
					this.search();
				},
				_initDom: function () {
					this.activeNavIndex = 0;
				},
				nav: function () {
					var _this = this;
					_this.data = [];//子菜单数据
					_this.asideFirstData = '';//初始左侧的子菜单
					_this.getInitNavdata();
					_this.renderAsideChild(_this.asideFirstData);//初始化渲染左侧菜单
					 var mySwiper = new Swiper('.swiper-container',{//滚动菜单渲染
									slidesPerView: 'auto',
						 			onSlideClick: function(swiper,e){
										if(e.target.className == 'nav-a'){
											var _theParent = $(e.target).parent();
											$(e.target).parents('.swiper-wrapper').find('.active').removeClass('active');
											_theParent.addClass('active');
											_this.activeNavIndex = _theParent.index();
											swiper.swipeTo(_theParent.index()-2);
											_this.renderAsideChild( JSON.parse(_theParent.attr('data-child')));
										}
											
											
										}
								})
							},
				getInitNavdata: function(){//渲染滚动导航，第一级数据
					let _this = this;
					commonUtils.loadDatas('/api/article/category',{ keyword: $('.J_search_input').val()},function(res){
								let navScrollHtml ='',isActive = '',childStr='',hasActiveflag = '';//默认选中第一个$('.J_search_input')
								for(let i=0;i< res.data.cate.length;i++){
										if(i==0){
											isActive = 'active';
											if(res.data.cate[0].hasOwnProperty('_child') && res.data.cate[0]._child.length>0){
													_this.asideFirstData = res.data.cate[0]._child;
											}else{
												_this.asideFirstData = [];
											}
											
										}else{
											isActive ='';
										}
										childStr = JSON.stringify(res.data.cate[i]._child);
												navScrollHtml += 	'<div class="swiper-slide red-slide '+ isActive +'" '+
													' style="width:100px;" data-child='+ childStr +'  data-id="'+ res.data.cate[i].id +'">'+
													'<a href="javascript:void(0);"'+
													' class="nav-a">'+ res.data.cate[i].name +'</a></div>';
											}
								$('.J_scroll_nav').html(navScrollHtml);
								
				} )	
				},
				renderAsideChild: function(datas){//填充左侧列表数据
					var _this = this;
					let tempAsideStr = '',isActive = '';
					var iframsSrc ='../mechanical/mechanical-list.html';
					if(!datas || datas.length == 0){
						$('.J_iframs').attr('src',iframsSrc + '?id='+ '-2000' );
					}
					for(let i=0; i< datas.length; i++){
									if(i==0){
											isActive = 'active';
											$('.J_iframs').attr('src',iframsSrc + '?id='+ datas[i].id );
										}else{
											isActive ='';
										}
						tempAsideStr += '<li class="'+ isActive +'"><a href="javascript:void(0);" data-tit="'+ datas[i].name +'" data-id='+ datas[i].id +' data-pid='+ datas[i].pid +'><span class="icon iconfont icon-youjiantou"></span>'+ datas[i].name +'</a></li>';
						
					}
					
					$('.J_aside_data').html(tempAsideStr);
					_this.setBread();
				},
				renderRightLists: function(datas){
					var _this = this;
					$('body').on('click','li',function(){
						var _the = $(this);
						var toUrl = '../mechanical/mechanical-list.html?id='+ _the.find('a').attr('data-id');
						var curUrl = $('.J_iframs').attr('src');
						if(toUrl == curUrl) return;
						_the.parent().find('.active').removeClass('active');
						_the.addClass('active');
						$('.J_iframs').attr('src','../mechanical/mechanical-list.html?id='+ _the.find('a').attr('data-id'));
						_this.setBread();
					});
			},
				setBread: function(){//设置底部面包屑
					var bread = ($('.J_scroll_nav').find('.active a').text()|| '...' )+ '&nbsp;&nbsp;-&nbsp;&nbsp;'+ ($('.J_aside_data').find('.active>a').attr('data-tit') || '....');
						$('.J_bread').html(bread); 
					
				},
				search: function(){//搜索
					var _this = this;
					$('.J_search_input').on('keypress',function(){
						if (event.keyCode == "13") {            
            		event.preventDefault(); 
            			//回车执行查询
									_this.nav();
            		
						}

						
					});
					
					
				}
					

			});
			return $internal; //返回对象
		}
	};
		$document.ready(function () {
			var HOMEPAGE = m_Homepage.createNew(); /* 定义首页页面类 */
			HOMEPAGE.init(); /* 调用首页页面类入口方法  */
			var srarchUrl = $('.J_srarchform').attr('action');
			//$('.J_srarchform').attr('action',ajaxHttpUrl + srarchUrl);
			HOMEPAGE.Methods.nav(); /* 当dom 加载完成后调用 banner 的呈现函数 */
			HOMEPAGE.Methods.renderRightLists();//绑定左侧导航点击事件
			
			
		});
	});

}());

